import complex_query from '@dfeidao/atom-nodejs/db/complex-query';
import query from '@dfeidao/atom-nodejs/db/query';
import log from '@dfeidao/atom-nodejs/logger/log';
import { IncomingHttpHeaders } from 'http';
import { productid, systemid } from '../../atom/config';
interface Message {
	// cookie: {
	// 	uk: string;
	// 	[key: string]: string
	// };
	// urls: {
	// 	base: string;
	// 	origin: string;
	// 	url: string;
	// };
	// query: {};
	// params: {};
	// headers: {};
	// captcha: string;
}

interface IWebResult {
	data: unknown;
	cookie?: {
		[name: string]: string;
	} | null;
	content_type?: string;
	headers?: {
		[key: string]: string;
	};
	attachment?: string;
	redirect?: string;
	status_code?: number;
}

export default async function atom(message: Message, action_id: string, session_id: string, headers: IncomingHttpHeaders): Promise<IWebResult> {
	log('Service begin path:f:\实习\kh\src\wyf-hManager\zj-000004\s001,action_id:' + action_id);
	// 获取隐患源评价级别下拉框数据
	const complex = complex_query(action_id, session_id, systemid);

	const com = await complex.add_field('basic_data', 'value_no', 'value_no').add_field('property_optional_values', 'optional_value', 'optional_value').where_eq('basic_data', 'value_name', 'assess_level').inner_join('basic_data', 'property_optional_values', ['value_no', 'value_no']).exec();

	// 获取隐患源管控层级下拉框数据
	const com1 = await complex.add_field('basic_data', 'value_no', 'value_no').add_field('property_optional_values', 'optional_value', 'optional_value').where_eq('basic_data', 'value_name', 'control_grade').inner_join('basic_data', 'property_optional_values', ['value_no', 'value_no']).exec();

	// 获取隐患源管控级别下拉框数据
	const com2 = await complex.add_field('basic_data', 'value_no', 'value_no').add_field('property_optional_values', 'optional_value', 'optional_value').where_eq('basic_data', 'value_name', 'control_level').inner_join('basic_data', 'property_optional_values', ['value_no', 'value_no']).exec();

	// 获取负责部门下拉框数据
	const { prepare, exec } = query(action_id, session_id, systemid);

	prepare('security_architecture', ['safety_department_name', 'safety_department_no'], { productid }, 200, 1, [], []);
	const [data] = await exec();

	log('Service end path:f:\实习\kh\src\wyf-hManager\zj-000004\s001,action_id:' + action_id);
	return {
		data: { com, com1, com2, data }
	};
}
